import 'package:flutter/material.dart';

class ListViewCase extends StatelessWidget {
  const ListViewCase({Key? key}) : super(key: key);
  List<Widget> getlist() {
    List<Widget> list = [];
    for (var i = 0; i < 10; i++) {
      list.add(Container(
        width: double.infinity,
        margin: EdgeInsets.all(10),
        decoration: BoxDecoration(
            color: Colors.blue, borderRadius: BorderRadius.circular(10)),
        child: Text(
          '第$i个',
          style: TextStyle(color: Colors.white, fontSize: 30),
        ),
      ));
    }

    return list;
  }

  @override
  Widget build(BuildContext context) {
    // 列表1 for循环
    // return ListView(
    //   children: getlist(),
    // );
    return ListView.builder(
      itemBuilder: (BuildContext context, int index) {
        return Container(
          width: double.infinity,
          margin: EdgeInsets.all(10),
          decoration: BoxDecoration(
              color: Colors.blue, borderRadius: BorderRadius.circular(10)),
          child: Text(
            '第${index + 1}个',
            style: TextStyle(color: Colors.white, fontSize: 30),
          ),
        );
      },
      itemCount: 5,
    );
  }
}
